
from PyQt5 import QtCore, QtGui, QtWidgets
import sys

# *************************通过ui文件转换得到的python代码**********************************
class Ui_Form(object):
    def setupUi(self, Form):
        Form.setObjectName("Form")
        Form.resize(400, 300)
        self.label = QtWidgets.QLabel(Form)
        self.label.setGeometry(QtCore.QRect(160, 80, 51, 51))
        self.label.setStyleSheet \
            ("background-color: rgb(58, 111, 50);\n""border-radius: 25px; border:\n"" 3px groove gray;border-style: outset;")

        self.label.setText("")
        self.label.setObjectName("label")
        self.pushButton1 = QtWidgets.QPushButton(Form)
        self.pushButton1.setGeometry(QtCore.QRect(150, 170, 75, 23))
        self.pushButton1.setObjectName("pushButton")
        self.pushButton2 = QtWidgets.QPushButton(Form)
        self.pushButton2.setGeometry(QtCore.QRect(150, 210, 75, 23))
        self.pushButton2.setObjectName("pushButton2")

        self.retranslateUi(Form)
        QtCore.QMetaObject.connectSlotsByName(Form)

    def retranslateUi(self, Form):
        _translate = QtCore.QCoreApplication.translate
        Form.setWindowTitle(_translate("Form", "指示灯"))
        self.pushButton1.setText(_translate("Form", "开灯"))
        self.pushButton2.setText(_translate("Form", "关灯"))


# *************************功能实现代码**********************************
# 自定义一个类，继承上面的类，来生成一个界面
class MyWindow(QtWidgets.QWidget ,Ui_Form):
    def __init__(self):
        super(MyWindow ,self).__init__()
        self.setupUi(self)  # 生成界面

        self.pushButton1.clicked.connect(self.open_light)   # 按钮1连接到函数 open_light()
        self.pushButton2.clicked.connect(self.close_light)  # 按钮2连接到函数 close_light()

    # 开灯（改变标签背景为高亮的颜色）
    def open_light(self):
        self.label.setStyleSheet \
            ('''QLabel{background-color: rgb(0, 234, 0);border-radius: 25px; border: 3px groove gray;border-style: outset;}''')

    # 关灯（改变标签背景为比较暗的颜色）
    def close_light(self):
        self.label.setStyleSheet \
            ('''QLabel{background-color: rgb(58, 111, 50);border-radius: 25px; border: 3px groove gray;border-style: outset;}''')


def state(val):
    val[0] = True


if __name__ == '__main__':
    val = {}
    state(val=val)
    print(val)
    exit()
    app = QtWidgets.QApplication(sys.argv)
    myshow = MyWindow()
    myshow.show()
    sys.exit(app.exec_())